<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Init Model
 *
 */
class Admin_settings_model extends CI_Model {

    /**
     * User data, stored for embeded methods
     *
     * @access 	private
     * @var 	array
     */
    var $settings = array();

    /**
     * Constructor
     *
     * @uses 	get_settings
     * @return 	void
     */
    function __construct() {
        parent::__construct();
        log_message('debug', 'Init Model Initialized');
        $this->get_settings();
    }

    /**
     * Get Settings
     *
     * Get all the auto loaded settings from the db.
     *
     * @return	array
     */
    function get_settings() {
        if (!$this->db->table_exists('web_settings')) {
            //redirect('setup');
            //print "Error! Can't Load Setting Data..";
            return FALSE;
        }
        $this->db->select('variable,value')->from('web_settings')->where('auto', '1');
        $query = $this->db->get();
        foreach ($query->result() as $k => $row) {
            $this->settings[$row->variable] = $row->value;
        }
        return $this->settings;
    }

    /**
     * Get Setting (Notice Singular)
     *
     * Used to pull out one specific setting from the settings table.
     * */
    function get_setting($name) {
        if (!empty($this->settings[$name])) {
            return $this->settings[$name];
        } else {
            $this->db->select('value')->from('web_settings')->where('variable', $name);
            $query = $this->db->get();
            if ($query->num_rows() > 0) {
                $row = $query->row();
                return $row->value;
            }
            return FALSE;
        }
    }

    function settings_detail() {
        $this->db->select('*');
        $query = $this->db->get('web_settings');
        $result = $query->result();
        return $result;
    }

    function social_media($id=NULL) {
        $sql = "Select value from web_settings where id=$id; ";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row)
            return $row->value;
        else
            return 0;
    }

}

?>